package com.opesoft.fw.mvc.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;

public abstract class InputBase extends FormBase
{
	protected String name;
	protected String value;
	protected String other;

	protected Form form; // 父标签

	public int doStartTag() throws JspException
	{
		this.initForm();
		return Tag.EVAL_BODY_INCLUDE;
	}

	public int doEndTag() throws JspException
	{
		this.form=null;
		this.value=null;
		this.other=null;
		return Tag.EVAL_PAGE;
	}

	/**
	 * 初始化父标签和this.value
	 * 
	 * @throws JspException
	 */
	protected void initForm() throws JspException
	{
		initParentForm();

		// 初始化自己的Value值
		if(value==null&&form!=null)
		{
			String result=form.getPropertyValue(name);
			if(result!=null) this.value=result;
			else this.value="";
		}
	}

	protected void initParentForm() throws JspException
	{
		Tag tag=this;
		while(!(tag instanceof Form)&&tag!=null)
		{
			tag=tag.getParent();
		}
		
		if(tag==null) throw new JspException("Input tag must have a parent tag as Form .");
		else this.form=(Form)tag;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name=name;
	}

	public String getOther()
	{
		return other;
	}

	public void setOther(String other)
	{
		this.other=other;
	}

	public String getValue()
	{
		return value;
	}

	public void setValue(String value)
	{
		this.value=value;
	}
}
